package com.peng.rpc.test.netty;

import com.peng.rpc.api.*;
import com.peng.rpc.loadBalance.RoundRobinLoadBalance;
import com.peng.rpc.netty.client.NettyRpcClient;
import com.peng.rpc.common.client.RpcClientProxy;
import com.peng.rpc.serializer.CommonSerializer;

/**
 * Netty客户端，定位在10000端口
 * @author wds
 */
public class NettyTestClient {

    public static void main(String[] args) {
        NettyRpcClient rpcClient = new NettyRpcClient(CommonSerializer.PROTOBUF_SERIALIZER, new RoundRobinLoadBalance());
        RpcClientProxy rpcClientProxy = new RpcClientProxy(rpcClient);
        HelloService helloService = rpcClientProxy.getProxy(HelloService.class);
        HelloObject helloObject = new HelloObject(11, "zhangsan");
        LoverArg loverArg = new LoverArg();
        loverArg.addLover("sister", "ChuYuan", 16)
                .addLover("yandere", "DonfangLingren", 16)
                .addLover("childhood", "XueZiyuan", 23)
                .addLover("miss", "RuanMubai", 27);
        for (int i = 0; i < 10; i++) {
            String res = helloService.hello(helloObject);
            System.out.println(res);

            HandShakeArg handShakeArg = new HandShakeArg("Lee Sin", "How Are You ?");
            HandShakeService handShakeService = rpcClientProxy.getProxy(HandShakeService.class);
            System.out.println(handShakeService.greet(handShakeArg));

            LoveService loveService = rpcClientProxy.getProxy(LoveService.class);
            LoverArg.Lover chosen = loveService.marry(loverArg);
            System.out.println("选择了 ==> " + chosen);
        }
    }

}
